/* document.querySelector('#btn-login').addEventListener('click', async () => {
    const form = document.querySelector('.login-form')
    const data = serialize(form, { empty: true, hash: true })
    const { username, password } = data
    if (username.trim() === '' || password.trim() === '') return showToast('用户名或密码不能为空')
    try {
        const res = await axios.post('/login', data)
        localStorage.setItem('my-token', res.data.token)
        localStorage.setItem('my-username', res.data.username)
        showToast('登录成功')
        setTimeout(() => {
            location.href = './index.html'
        }, 800)




    } catch (error) {
        showToast('登录失败')
    }
}) */
document.querySelector('#btn-login').addEventListener('click', async () => {
    const form = document.querySelector('.login-form')
    const data = serialize(form, { empty: true, hash: true })
    const { username, password } = data
    if (username.trim() === '' || password.trim() === '') {return showToast('用户名或密码不能为空')}

    //设置账号密码长度

    
    try {
        const res = await axios.post('/login', data)
        localStorage.setItem('my-token', res.data.token)
        localStorage.setItem('my-username', res.data.username)
        showToast('登录成功')
        setTimeout(() => {
            location.href = './index.html'
        }, 800) 
    } catch (error) {
        showToast('登录失败')


    }
    
})
